home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / asm / clockjc.exe / CLOCK.ASM < prev    next >
Assembly Source File  |  1992-10-21  |  9KB  |  327 lines

  1. ; To create the EXE file copy makefile and clock.asm into
  2. ; the same directory and run MAKE.
  3. ; Compiled with TASM 3.1
  4. ; Linked with TLINK 3.1
  5.  
  6. ; Clock - Assembly language clock in .EXE format
  7. ; This program creates screen clock in the upper right hand corner
  8. ; of the screen. Format HH:MM:SS. This program creates the clock then
  9. ; waits for keyboard input and removes the clock.
  10. ; The clock itself is installed as an ISR using
  11. ; INT 1C, USER TIMER TICK, which tick 18 times per second.
  12. ; See the comments in the code for exact implementation details
  13. ;
  14. ; This code is given to the public domain and is free. The only 
  15. ; condition is that it be distributed without modifications of
  16. ; any kind.
  17.  
  18. ; Author: Joe L. Chavez
  19. ; CIS [75470, 3627]
  20.  
  21. ; Creation Date: 10/21/92
  22.  
  23.  
  24. DOSSEG          ;indicate DOS segment conventions
  25. .8086           ;select the processor
  26. .MODEL SMALL    ;select the model
  27. .STACK 2000h    ;reserve stack space as needed for application
  28.  
  29. .DATA
  30. ;       clock data area
  31.  
  32. ESSEG   DW      ?
  33. CLKFLG  DB      1                       ;clock on/off flag
  34. SEC     DB      0                       ;second (binary)
  35. MIN     DB      0                       ;minute
  36. HOU     DB      0                       ;hour
  37. TICCNT  DB      18                      ;tick counter
  38. SECCNT  DB      0                       ;second counter (for calibration)
  39. CPOS    DW      0                       ;cursor position
  40. CMODE   DB      0                       ;current video state
  41. MODES   DB      0,1,2,3,1,0,2,2         ;decoded modes
  42. TIMSTR  DB      ' '                     ;space before time
  43. HOUR    DW      0                       ;hour (ascii)
  44.     DB      ':'
  45. MINUTE  DW      0                       ;minute
  46.     DB      ':'
  47. SECOND  DW      0                       ;second
  48.  
  49.  
  50. ; Constants
  51.  
  52. CYAN    EQU     011B
  53.  
  54. COLOR   EQU     CYAN                    ;clock color
  55. ROW     EQU     0                       ;put clock on top row
  56. SCRINT  EQU     10H                     ;screen control interrupt
  57. SCP     EQU     2                       ;set cursor position
  58. GCP     EQU     3                       ;get curosr position
  59. WCHAR   EQU     9                       ;write character
  60. GVS     EQU     15                      ;get video state
  61.  
  62.  
  63.  
  64. .CODE
  65.     ;This marks the start of executable code
  66.     .startup
  67.     ;EXE program has all available memory allocated to it
  68.                     
  69.                     ; get time on new second
  70.     MOV     AH,2CH
  71.     INT     21H                     ;get time
  72.     MOV     SEC,DH                  ;save second
  73. NEWSEC: MOV     AH,2CH
  74.     INT     21H                     ;get time again
  75.     CMP     SEC,DH                  ;same second?
  76.     JZ      NEWSEC                  ;wait for a new second
  77.     MOV     SEC,DH                  ;set seconds
  78.     MOV     WORD PTR MIN,CX         ;set minutes, hours
  79.  
  80.  
  81.         ; preserve the registers
  82.     PUSH    AX
  83.     PUSH    BX
  84.     PUSH    CX
  85.     PUSH    DX
  86.     PUSH    SI
  87.     PUSH    DI
  88.     PUSH    DS
  89.     PUSH    ES
  90.     PUSH    BP
  91.         ; save ES so it can be used in Clock
  92.     MOV     ESSEG, ES
  93.  
  94.         ; disable ints while installing new ISR
  95.     CLI
  96.  
  97.     ; save old int
  98.     MOV     AX, 351Ch
  99.     INT     21h     
  100.  
  101.         ; here we store the Old INT 1C in a
  102.         ; memory location that resides in the 
  103.         ; code segment so that it can be called 
  104.         ; in Clock without knowing the correct DS
  105.  
  106.     MOV     WORD PTR CS:OLDINT1C, BX
  107.     MOV     WORD PTR CS:OLDINT1C+2, ES
  108.  
  109.  
  110.     ; set new int 1C
  111.     MOV     AX, 251Ch
  112.     MOV     DX, SEG Clock
  113.     MOV     DS, DX
  114.     MOV     DX, OFFSET Clock
  115.     INT     21h
  116.  
  117.  
  118.     ; enable interrupts
  119.     STI
  120.  
  121.  
  122. L1:     
  123.     ; now get a char
  124.     MOV     AH, 1 
  125.     INT     16h
  126.     JNZ     QUIT
  127.     JMP     L1
  128.  
  129.     ; to restore the old int vector
  130. QUIT:   
  131.  
  132.     ; disable interrupts while installing Old INT 1C
  133.     CLI
  134.     MOV     AX, 251Ch
  135.     MOV     DX, WORD PTR CS:OLDINT1C
  136.     MOV     BX, WORD PTR CS:OLDINT1C+2
  137.     MOV     DS, BX
  138.     INT     21h
  139.     STI
  140.  
  141.     ; restore the regs
  142.     POP     BP
  143.     POP     ES
  144.     POP     DS
  145.     POP     SI
  146.     POP     DI
  147.     POP     DX
  148.     POP     CX
  149.     POP     BX
  150.     POP     AX
  151.  
  152.     ;Exit to DOS when complete
  153.     MOV AX,4C01H
  154.     INT 21H
  155.     RET
  156.  
  157. ; this is the pointer to the FAR address
  158. ; of the Old INT 1C procedure
  159. OLDINT1C DD      ?
  160.  
  161. ;Arguments to this procedure:
  162. ;ES=PSP address (for command-line arguments)
  163. ;Must return an exit value in AL
  164.  
  165. Clock   PROC NEAR
  166.  
  167.     ; preserve the regs used in this proc
  168.     PUSH    DS
  169.     PUSH    ES
  170.     PUSH    AX
  171.  
  172.     ; get the DATA & EXTRA segment for this program
  173.     MOV     AX, @DATA
  174.     MOV     DS, AX
  175.     MOV     AX, ESSEG
  176.     MOV     ES, AX
  177.     
  178.     ; start clock processing        
  179.     DEC     TICCNT               ;decrement tick counter
  180.     JNZ     RT1                  ;not timed out
  181.     MOV     TICCNT,18            ;else, reset tick counter
  182.  
  183.     MOV     AL,SEC               ;get seconds
  184.     INC     AL                   ;add one
  185.     CMP     AL,60                ;60 seconds?
  186.     MOV     SEC,AL               ;reset seconds
  187.     JNZ     CHKFLG               ;not a minute, check flag
  188.     MOV     SEC,0                ;else, zero seconds
  189.     MOV     AL,MIN               ;get minutes
  190.     INC     AL                   ;add one
  191.     CMP     AL,60                ;60 minutes?
  192.     MOV     MIN,AL               ;reset minutes
  193.     JNZ     CHKFLG               ;not an hour
  194.     MOV     MIN,0                ;else, zero minutes
  195.     MOV     AL,HOU               ;get hour
  196.     INC     AL                   ;add one
  197.     CMP     AL,24                ;24 hours?
  198.     MOV     HOU,AL               ;reset hours
  199.     JNZ     CHKFLG               ;not a day
  200.     MOV     HOU,0                ;else, zero hour
  201. CHKFLG: CMP     CLKFLG,0             ;clock enabled?
  202.     JZ      RT1                  ;if so, update screen clock
  203.     CALL    UPDATE                  
  204. RT1:    
  205.  
  206.     ; restore the regs
  207.     POP     AX
  208.     POP     ES
  209.     POP     DS
  210.     ; setup for the call to the Old INT 1C
  211.     PUSHF
  212.     CALL    CS:OLDINT1C
  213.     IRET
  214.  
  215. Clock   ENDP
  216.  
  217.  
  218. ; Update the screen
  219.  
  220. UPDATE  PROC NEAR
  221.  
  222.     ; preserver regs used by this procedure
  223.  
  224.     PUSH    AX
  225.     PUSH    BX
  226.     PUSH    CX
  227.     PUSH    DX
  228.     PUSH    SI
  229.     PUSH    DI
  230.     PUSH    BP
  231.  
  232.     MOV     CLKFLG,0
  233.     MOV     AL,HOU                  ;get hours
  234.     CALL    CONASC                  ;convert to ascii
  235.     MOV     HOUR,AX                 ;result to buffer
  236.     MOV     AL,MIN                  ;get minutes
  237.     CALL    CONASC                  ;convert to ascii
  238.     MOV     MINUTE,AX               ;result to buffer
  239.     MOV     AL,SEC                  ;get seconds
  240.     CALL    CONASC                  ;convert to ascii
  241.     MOV     SECOND,AX               ;result to buffer
  242.     MOV     AH,GVS
  243.     INT     SCRINT                  ;get video state
  244.     PUSH    BX                      ;save page
  245.     MOV     BX,OFFSET MODES         ;point to video modes
  246.     XLAT                            ;get mode code
  247.     MOV     CMODE,AL                ;save decoded mode
  248.     POP     BX                      ;get page
  249.     MOV     AH,GCP
  250.     INT     SCRINT                  ;get cursor position
  251.     MOV     CPOS,DX                 ;save it
  252.     MOV     DH,ROW                  ;get row for clock
  253.     MOV     DL,31                   ;assume column 31
  254.     CMP     BYTE PTR CMODE,2        ;80 column mode?
  255.     JB      PTIME0                  ;no
  256.     MOV     DL,71                   ;else, set column 71
  257. PTIME0: MOV     AH,SCP
  258.     INT     SCRINT                  ;set cursor position to time area
  259.     MOV     CX,9                    ;set a counter
  260.     MOV     BL,WHITE                ;assume white color
  261.     CMP     BYTE PTR CMODE,0        ;40 column B/W?
  262.     JZ      PTIME1                  ;yes
  263.     CMP     BYTE PTR CMODE,2        ;80 column B/W?
  264.     JZ      PTIME1
  265.     MOV     BL,COLOR                ;else, use color
  266. PTIME1: MOV     SI,OFFSET TIMSTR        ;point to time string
  267. PTMLP:  LODSB                           ;get a digit
  268.     PUSH    CX                      ;save counter
  269.     PUSH    SI                      ;save pointer
  270.     CALL    PDIGIT                  ;print digit
  271.     POP     SI
  272.     POP     CX
  273.     LOOP    PTMLP                   ;loop until done
  274. PDONE:  MOV     AH,SCP
  275.     MOV     DX,CPOS
  276.     INT     SCRINT                  ;restore cursor to user's position
  277.  
  278.     MOV     CLKFLG,1
  279.  
  280.     ; restore the regs
  281.  
  282.     POP     BP
  283.     POP     DI
  284.     POP     SI
  285.     POP     DX
  286.     POP     CX
  287.     POP     BX
  288.     POP     AX
  289.  
  290.     RET
  291.  
  292. UPDATE  ENDP
  293.  
  294.  
  295. CONASC  PROC NEAR
  296.